## This file runs all the code necessary for replicating the empirical example
## on democracy appearing in Chiu and Xu (2021)

# please set path and source helper.r
setwd(rep_path)
source("helper.R")


# Python
reticulate::use_condaenv("BRS_conda")  ## use this conda environment for BRS


## Part I: Packages and data -----------------------
# Load packages
require(doParallel)
require(dplyr)
require(BRS)
require(QCA)
require(ggplot2)
require(cowplot)
require(circlize)
require(RColorBrewer)
require(prettyGraphs)
require(Rtsne)
require(kableExtra)
require(ggpattern)

# Load and format data and create necessary labels and other objects
source("lipset/lipset_make-data.R")



## PART II: Run BRS -----------------------
# Run BRS with bootstrapping (this will take 5-10 minutes)
# The code in the following chunk will produce "lipset_out_pois.rda"
if (FALSE) {
	source("lipset/lipset_pois.R")
}


## Part III: Make graphs -----------------------

# requires "lipset/out/lipset_out_pois.rda"

# Make figures and tables that appear in the paper
# figures will be saved in the "figures" folder
source("lipset/lipset_bar.R") # Figure 1
source("lipset/lipset_chord.R")  # Figure 2a
source("lipset/lipset_tsne.R") # Figure 2b

# table will be saved in the "tables" folder
source("lipset/lipset_tt.R") # Table 2 and Table A4


